<?php
namespace app\admin\controller;

class Index extends Base{
    //
    public function index(){
        //$this->view->config('strip_space', true);
        $this->assign('menu', $this->init());
        return $this->fetch('', ['user'=>$this->userInfo]);
    }
    //
    public function main(){
        $info = [
            '操作系统'=>PHP_OS,
            '运行环境'=>$_SERVER["SERVER_SOFTWARE"],
            'PHP运行方式'=>php_sapi_name(),
            //'ThinkPHP版本'=>THINK_VERSION.' [ <a href="javascript:void(0)" >查看最新版本</a> ]',
            '上传附件限制'=>ini_get('upload_max_filesize'),
            '执行时间限制'=>ini_get('max_execution_time').'秒',
            '服务器时间'=>date("Y年m月d日 H:i:s"),
            '北京时间'=>gmdate("Y年m月d日 H:i:s",time()+8*3600),
            '服务器域名/IP'=>$_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
            '剩余空间'=>round((@disk_free_space(".")/(1024*1024*1024)),2).'G',
            'register_globals'=>get_cfg_var("register_globals")=="1" ? "ON" : "OFF",
            'magic_quotes_gpc'=>(1===get_magic_quotes_gpc())?'YES':'NO',
            'magic_quotes_runtime'=>(1===get_magic_quotes_runtime())?'YES':'NO',
        ];
        $this->view->engine->layout(false);
        $this->assign('info', $info);
        return $this->fetch();
    }
    //
    public function init(){
        $menu = [];
        $module = model('module');
        $gfArr = $module->where('fid', '=', 0)->where('display', '=', 1)->order('sort', 'asc')->select()->toArray();
        foreach($gfArr as $key1 => $row1){
            $menu[$key1]['name'] = $row1['title'];
            $menu[$key1]['faicon'] = $row1['faicon'];
            $menu[$key1]['tree'] = [];
            $fArr = $module->where('fid', '=', $row1['id'])->where('display', '=', 1)->order('sort', 'asc')->select()->toArray();
            foreach($fArr as $key2 => $row2){
                $menu[$key1]['tree'][$key2]['name'] = $row2['title'];
                $menu[$key1]['tree'][$key2]['faicon'] = $row2['faicon'];
                $menu[$key1]['tree'][$key2]['tree'] = [];
                $sArr = $module->where('fid', '=', $row2['id'])->where('display', '=', 1)->order('sort', 'asc')->select()->toArray();
                foreach($sArr as $key3 => $row3){
                    if(!authcheck('Admin/'.$row3['module'].'/index')){
                        continue;
                    }
                    $menu[$key1]['tree'][$key2]['tree'][$key3]['name'] = $row3['title'];
                    $menu[$key1]['tree'][$key2]['tree'][$key3]['url'] = url($row3['module'].'/index');
                    $menu[$key1]['tree'][$key2]['tree'][$key3]['faicon'] = $row3['faicon'];
                }
            }
        }//print_r($menu);exit;
        return [['name'=>'主菜单','tree'=>$menu]];
    }
    //
    public function clear(){
        //shell_exec('/alidata/server/php/bin/php '.dirname(dirname(dirname(__DIR__))).'/think clear --log --dir');
        //shell_exec('/alidata/server/php/bin/php '.dirname(dirname(dirname(__DIR__))).'/think clear --cache --dir');
        //shell_exec('/alidata/server/php/bin/php '.dirname(dirname(dirname(__DIR__))).'/think clear --route');
        $result = ['code'=>1, 'msg'=>'服务端清理缓存成功'];
        return json($result);
    }
}